package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import www.woniuxy.com.class112.entity.AgriculturalMarket;
import www.woniuxy.com.class112.form.insertProductInfoForm;
import www.woniuxy.com.class112.form.selectProductForm;
import www.woniuxy.com.class112.param.insertProductInfoParam;
import www.woniuxy.com.class112.param.selectProductParam;
import www.woniuxy.com.class112.service.ProductService;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product")
@Api(tags = "农产品相关接口")
public class ProductController {
    @Resource
    private ProductService productService;
    @PostMapping("/insertProductInfo")
    @ApiOperation("新增农产品详情")
    public Result insertProductInfo(@RequestBody insertProductInfoForm form)throws Exception{
        productService.insertProductInfo(BeanUtil.toBean(form, insertProductInfoParam.class));
        return Result.success("新增农产品详情成功",null);
    }
    @GetMapping("/enableProduct")
    @ApiOperation("启用农产品详情")
    public Result enableProduct(Long productId)throws Exception{
        productService.enableProduct(productId);
        return Result.success("启用农产品详情成功",null);
    }
    @GetMapping("/disableProduct")
    @ApiOperation("禁用农产品详情")
    public Result disableProduct(Long productId)throws Exception{
        productService.disableProduct(productId);
        return Result.success("禁用农产品详情成功",null);
    }
    @PostMapping("/redactProduct")
    @ApiOperation("修改农产品详情")
    public Result redactProduct(@RequestBody AgriculturalMarket form)throws Exception{
        productService.redactProduct(form);
        return Result.success("修改农产品详情成功",null);
    }
    @PostMapping("/selectProduct")
    @ApiOperation("搜索农产品详情")
    public Result selectProduct(@RequestBody selectProductForm form)throws Exception{
        return Result.success("搜索农产品详情成功",productService.selectProduct(BeanUtil.toBean(form, selectProductParam.class)));
    }
    @PostMapping("/userselectProduct")
    @ApiOperation("用户搜索农产品详情")
    public Result userselectProduct(@RequestBody selectProductForm form)throws Exception{
        return Result.success("搜索农产品详情成功",productService.userselectProduct(BeanUtil.toBean(form, selectProductParam.class)));
    }
    @GetMapping("/deleteProduct")
    @ApiOperation("删除农产品详情")
    public Result deleteProduct(Long productId)throws Exception {
        productService.deleteProduct(productId);
        return Result.success("删除农产品详情成功", null);
    }
}
